package com.example.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.ContextMenu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.ImageView
import android.widget.Toast

class ContextMenuActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_context_menu)

        val image = findViewById<ImageView>(R.id.context_image)
        //注册到activity的上下文中
        registerForContextMenu(image)
    }

    override fun onCreateContextMenu(
        menu: ContextMenu?,
        v: View?,
        menuInfo: ContextMenu.ContextMenuInfo?
    ) {
        val menuInflater = MenuInflater(this)
        menuInflater.inflate(R.menu.context_menu,menu)
    }

    override fun onContextItemSelected(item: MenuItem): Boolean {
        var intent:Intent? = null
        when(item.itemId){
            R.id.collect ->  Toast.makeText(this,"图片已经收藏!",Toast.LENGTH_SHORT).show()
            R.id.report ->  Toast.makeText(this,"已经举报，等待审核!",Toast.LENGTH_SHORT).show()
        }
        return super.onContextItemSelected(item)
    }
}